﻿#ifndef YUTOPP_TWITPIC_CLIENT_HPP
#define YUTOPP_TWITPIC_CLIENT_HPP

#include "../basic_client.hpp"

#include "policy.hpp"
#include "request.hpp"

#include "../twitter.hpp"


namespace webapp
{
	namespace clients
	{
		namespace twitpic
		{
			template<class Protocol = protocol::http, class Policy = policy::v2>
			class client
				: public basic_client<client<Protocol, Policy>, Protocol, Policy>
			{
				typedef basic_client<client<Protocol, Policy>, Protocol, Policy>	base_type;

				friend base_type;

			public:
				typedef typename base_type::auth_type		auth_type;
				typedef typename base_type::auth_key_type	auth_key_type;
				typedef typename base_type::string_type		string_type;
				typedef typename base_type::binary_type		binary_type;
				typedef typename base_type::header_type		header_type;

				explicit client( const binary_type& key )
					: key_( key )
				{}

				client( const auth_key_type& auth_key, const binary_type& key )
					: base_type( auth_key )
					, key_( key )
				{}

				template<class Protocol_, class Policy_>
				client( const twitter::client<Protocol_, Policy_>& twitter, const binary_type& key )
					: base_type( twitter.get_auth_key() )
					, key_( key )
				{}
		
				/*template<class Protocol_, class Policy_>
				void link_to_twitter( const twitter::client<Protocol_, Policy_>& twitter )
				{
					auth_.set_key( twitter.get_auth_key() );
				}*/
		
				//
				void set_key( const binary_type& key )
				{
					key_ = key;
				}
				const binary_type& get_key() const
				{
					return key_;
				}
		
			private:
				header_type request_field(
					const auth_type& auth,
					const binary_type&
					) const
				{
					return boost::assign::map_list_of<binary_type, binary_type>
						( "X-Auth-Service-Provider"
							, "https://api.twitter.com/1/account/verify_credentials.json" )
						( "X-Verify-Credentials-Authorization"
							, auth.make_header(
								"GET",
								"https://api.twitter.com/1/account/verify_credentials.json" )
								+ ", realm=\"" + url::encode( "http://api.twitter.com/" ) + "\""
							);
				}

				binary_type key_;
			};
		}
	}
}

#endif /*YUTOPP_TWITPIC_CLIENT_HPP*/
